﻿var modalApproveReport;

$().ready(function () {
    modalApproveReport = new ModalApproveReport();
    modalApproveReport.Initialize();
});

function ModalApproveReport() {
    var _this = this;
    var ajaxUrl = "/Developer/ApproveReport";
    var dialogName = "#modalApproveTask";
    var itemID;

    this.Initialize = function () {
        _this.dialogInstance().dialog({
            autoOpen: false,
            width: "435px",
            resizable: false,
            modal: true,

            buttons: {
                "Confirm": function () {
                    _this.execute(itemID);
                    $(this).dialog("close");
                },
                "Cancel": function () {
                    $(this).dialog("close");
                }
            }
        });

        $(".status").click(function () {
            itemID = $(this).siblings(".report-id").val();
            _this.open();
        });
    }

    this.dialogInstance = function () {
        return $(dialogName);
    }
    this.open = function () {
        _this.dialogInstance().dialog("open");
    }
    this.close = function () {
        _this.dialogInstance().dialog("close");
    }

    this.execute = function (ID) {
        var dataAjax = {
            id: ID,
            hours: $("#hours", _this.dialogInstance()).attr("value")
        };

        $.ajax(
        {
            type: "POST",
            url: ajaxUrl,
            data: dataAjax,
            success: function (data) {
                if (data.result == "ok") {
                    window.location.replace(document.location.href);
                }
                else {
                }
            },
            error: function () {
                alert("Error");
            }
        });
    }
}